package qdu.edu.com.fushanf4.item_desc_dataset.txt.count;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ProductCountMapper extends Mapper <LongWritable, Text, Text, IntWritable>{
    private final Text keyOut = new Text();
    private final static IntWritable valueOut = new IntWritable(1);

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String[] splits = value.toString().split("\t");

        if (splits.length <= 1) {    // 防止不干净的数据导致数组越界，有些数据可能并不符合一本性的规则，导致出人意料的结果
            return;
        }

 //       String products = splits[0];

        keyOut.set(splits[0]);
        context.write(keyOut, valueOut);
    }
}
